package cn.zqy.demo2.day06.ThreadSafe;
//  实现卖票案例
public class RunnableTicketImpl implements Runnable{
    //定义一个多个线程共享的票源
    private int ticket = 100;
    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                try {
                    //提高安全问题出现的概率,让程序睡眠
                    Thread.sleep(10);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                break;
            }
            System.out.println(Thread.currentThread().getName()+ "正在卖第： " + ticket-- + "张票");
        }
    }
}
